package chd.edu.train.business.controller.admin;

import chd.edu.train.business.req.TrainCarriageQueryReq;
import chd.edu.train.business.req.TrainCarriageSaveReq;
import chd.edu.train.business.resp.TrainCarriageQueryResp;
import chd.edu.train.business.service.TrainCarriageService;
import chd.edu.train.common.resp.CommonResp;
import chd.edu.train.common.resp.PageResp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhang Chaoliang
 * create 2023
 */
@RestController
@RequestMapping("/admin/train-carriage")
public class TrainCarriageAdminController {

    @Resource
    private TrainCarriageService trainCarriageService;

    /**
     * 保存/修改编辑信息
     * @param req
     * @return
     */
    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody TrainCarriageSaveReq req){
        trainCarriageService.save(req);

        return new CommonResp<>();
    }

    /**
     * 保存信息
     * @param req
     * @return
     */
    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainCarriageQueryResp>> queryList(@Valid TrainCarriageQueryReq req){
        PageResp<TrainCarriageQueryResp> list = trainCarriageService.queryList(req);

        return new CommonResp<>(list);
    }

    /**
     * 删除信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        trainCarriageService.delete(id);

        return new CommonResp<>();
    }

}
